<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/metisMenu/metisMenu_custom.css" />
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../static/jqueryValidate/jquery.validate.min.js"></script>
<script src="../static/jqueryValidate/additional-methods.min.js"></script>
<script src="../static/jqueryValidate/localization/messages_zh.min.js"></script>
<script src="../static/js/base-loading.js"></script>
<title>项目管理</title>
</head>
<body>
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">子项目列表</div>
		</div>

	</div>
	<div class="table-container" data-options="region:'center'">
		<div>
			<table id="child_table" class="easyui-datagrid" style="min-height: 100%">
			</table>
		</div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro =[[${projectitem}]];
	var currentChild;
	$(document).ready(function() {
		$('#child_table').datagrid({
			rownumbers : true,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			toolbar : '#child_tb',
			url : "../projectitemchilds?projectitemid=" + currentPro.id,
			method : 'get',
			onSelect : function(index,row) {
				currentChild = row;
			},
			columns : [ [ {
				field : 'name',
				title : '项目名',
				width : '100%',
				formatter : function(value,row,index) {
					var html = '';
					html += '<div class="info info-mypro"><div class="info-item-name" style="width:'+ ellipsis(32) +'px;margin-bottom:10px;">'+ row.projectno +'</div><div class="info-item-content" style="width:'+ ellipsis(0) +'px;">'+ row.name+'</div>';
					html += '<div class="info-time"><span>该项目从'+ formatDate(row.startdate) +'起</span>'
					html += '<span>至'+ formatDate(row.enddate) +'结束</span></div>'
					html += '<div class="info-time info-time-fb">'
						if (row.creater){
							html +=  '<span>'+ row.creater.name +'</span>';
						}else{
							html ;
						}
					html += '<span>发布于'+ formatDate(row.createdate) +'</span></div>';
					if (row.status == 1){
						html += '<div class="info-status two">待确认</div>';
					}
					if (row.status == 2){
						html += '<div class="info-status green">进行中</div>';
					}
					if (row.status == 3){
						html += '<div class="info-status refuse">废止</div>';
					}
					if (row.status == 5){
						html += '<div class="info-status ok">结束</div>';
					}
					html += '<div class="edit"><span class="info-edit" onclick="updatechild('+index+')"></span></div></div>';
					return html;
				}	
			}] ]
		});
	});
	function ellipsis(value){
		var WIDTH = $("body").width();
		WIDTH-=10;
		var width;
		width = WIDTH-value
		return width;
	}
	function newchild() {
		window.location.href = "../app/projectitemchildadd2.do?projectitemid=" + currentPro.id;
	}
	function updatechild(index) {
		var item = $("#child_table").datagrid('getRows')[index];
		window.location.href = "../app/projectitemchildadd2.do?id=" + item.id;
	}
	function deletechild(index) {
		var row = $("#child_table").datagrid('getRows')[index];
		if (row){
			$.messager.confirm("操作提示", "您确定要执行操作吗？", function(data) {
				if (data){
					var status;
					if (row.status == 2){
						status = 3;
					}else{
						$.messager.alert('警告', '该项目已废止', 'warning');
						return;
					}
					$.ajax({
						type : 'POST',
						url : "../ProjectItemChildDelete.do?id=" + row.id + "&&status=" + status,
						success : function(data) {
							if (data.success){
								$.messager.show({
									title : '操作',
									msg : '操作成功',
									timeout : 5000,
									showType : 'slide'
								});
								refreshChildTable();
							}else{
								$.messager.alert('操作', '操作失败', 'error');
							}
						},
						dataType : "json"
					});
				}
			});
		}else{
			$.messager.alert('操作', '请选择要禁用的子项目', 'warning');
		}
	}
	function refreshChildTable() {
		$('#child_table').datagrid("reload");
	}
	function formatDate(time) {
		var date = new Date(time);
		var year = date.getFullYear(),month = date.getMonth() + 1, //月份是从0开始的
		day = date.getDate(),hour = date.getHours(),min = date.getMinutes(),sec = date.getSeconds();
		var newTime = year + '-' + month + '-' + day;
		return newTime;
	}
</script>

</html>